//
//  LvXingDi.m
//  SeeTheWorld
//
//  Created by dllo on 16/2/29.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "LvXingDi.h"
#import "ModelOfLvXingDi.h"
#import "PCH.pch"
#import <UIImageView+WebCache.h>


@interface LvXingDi ()

@property (nonatomic, retain)UIImageView *imageOfBack;
@property (nonatomic, retain)UILabel *label;
@property (nonatomic, retain)NSMutableAttributedString *mAttStri;

@end

@implementation LvXingDi

- (void)dealloc {
    [_mAttStri release];
    [_imageOfBack release];
    [_label release];
    [super dealloc];
}


- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createSubviews];
        
    }
    return self;
}

- (void)createSubviews {
    
    self.imageOfBack = [[UIImageView alloc] init];
    [self.contentView addSubview:self.imageOfBack];
    [_imageOfBack release];
    
    
    self.label = [[UILabel alloc] init];
    [self.contentView addSubview:self.label];
    [_label release];
    self.label.textAlignment = NSTextAlignmentCenter;
    self.label.dk_textColorPicker = DKColorWithRGB(0x343434, 0xffffff);

}

#pragma mark - 布局子视图
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    
    self.imageOfBack.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height / 3 * 2);
    self.label.frame = CGRectMake(0, self.contentView.frame.size.height / 3 * 2, self.contentView.frame.size.width, self.contentView.frame.size.height / 3);
    
}

- (void)passModel:(ModelOfLvXingDi *)model {
    
    [self.imageOfBack sd_setImageWithURL:[NSURL URLWithString:model.image_url] placeholderImage:[UIImage imageNamed:@"1f178a82b9014a90e9109296ad773912b31beeeb"]];
    
    self.mAttStri = [[NSMutableAttributedString alloc] initWithString:model.name];
    NSRange range = [model.name rangeOfString:model.text];
    [self.mAttStri addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range];
    self.label.attributedText = self.mAttStri;
    
    
    
}





@end
